<?php

class LoadModel
{
    protected $registry;

    public function __construct($registry) {
        $this->registry = $registry;
    }

    public function __get($key) {
        return $this->registry->get($key);
    }

    public function __set($key, $value) {
        $this->registry->set($key, $value);
    }

    public function load($model=false)
    {
        $file=DIR_SYSTEM.'models/'.$model.'.php';
        if(!file_exists($file)) $file=DIR_SYSTEM.'models/'.$model.'Model.php';

        if(file_exists($file)){
            include_once($file);
            $class=ucfirst($model);
            return new $class($this->registry);
        }else{
            trigger_error('Error: Could not load model '.$model.'!');
            return false;
        }
    }
}